package com.lanlian.uikit;

import android.app.Dialog;
import android.content.Context;
import android.os.Handler;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

public class LoadingDialog extends Dialog {

    private TextView mTvMessage;

    public LoadingDialog(Context context) {
        this(context, R.style.loadingDialog);
    }

    public LoadingDialog(Context context, int styleId) {
        super(context, styleId);
        setContentView(R.layout.dialog_loading);
        mTvMessage = findViewById(R.id.tv_tips);
        Window dialogWindow = getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.y = -120;
        dialogWindow.setAttributes(lp);
    }

    public void setMessage(String message) {
        if (TextUtils.isEmpty(message)) {
            mTvMessage.setVisibility(View.GONE);
        } else {
            mTvMessage.setVisibility(View.VISIBLE);
            mTvMessage.setText(message);
        }
    }

    @Override
    public void dismiss() {
        super.dismiss();
    }

    @Override
    public void show() {
        super.show();
    }

    public void dismissDelayed() {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                dismiss();
            }
        }, 300);
    }

}
